<template>
<!-- 团课详细页面及报名功能-->
	<view class="container u-skeleton">
		<u-alert v-show="show" :title="title" type="warning" effect="dark" :description="description"></u-alert>
		<view class="userinfo">
			<!--u-skeleton-circle 绘制圆形-->
			<image class="userinfo-avatar u-skeleton-circle" :src="releaseCourseInfo.coverPic"></image>
			<!--u-skeleton-fillet 绘制圆角矩形-->
			<text class="u-skeleton-fillet">{{releaseCourseInfo.courseName}}</text>
		</view>
		<view style="margin: 20px 0">
			<text class="u-skeleton-fillet">{{releaseCourseInfo.courseDescribe}}</text>

		</view>
		<view style="margin: 20px 0">
			<view v-if="releaseCourseInfo.collectFee==0">
				<view class="tag01">
					<u-tag text="付费" type="error" size="mini"></u-tag>
				</view>
				<view class="price">
					价格:{{releaseCourseInfo.collectFeeMoney}}元
				</view>
			</view>
			<view v-if="releaseCourseInfo.collectFee==1">
				<view class="tag01">
					<u-tag text="免费" type="success" size="mini"></u-tag>
				</view>
			</view>
		</view>
		<view style="margin: 20px 0">

			<u-button type="primary" text="报名" @click="Registration"></u-button>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				show: false,
				title: "报名成功",
				userId: 2,
				id: '',
				releaseCourseInfo: {},
				CourseInfo: [],
			}
		},
		onLoad(options) {
			this.id = options.id
			this.queryAll()
		},
		methods: {
			// 课程的详细信息
			queryAll() {
				uni.request({
					url: 'http://127.0.0.1:8080/subscribe/courseSubscribe/queryAll',
					method: 'GET',
					data: {
						id: this.id
					}
				}).then((res) => {
					console.log(res)
					this.CourseInfo = res.data.rows
					this.releaseCourseInfo = this.CourseInfo[0]
				})
			},
			Registration() {

				uni.request({
					url: "http://127.0.0.1:8080/subscribe/courseSubscribe/saveRegistrationRecord",
					method: 'get',
					data: {
						registrationCourseName: this.releaseCourseInfo.courseName,
						courseId: this.id,
						userId: this.userId
						// course: this.releaseCourseInfo
					},
					success() {
						alert("报名成功")
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 20rpx 60rpx;
	}

	.userinfo {

		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.userinfo-avatar {

		width: 100%;
		height: 150px;
		margin: 20rpx;
		// border-radius: 50%;
	}


	.tag01 {
		float: left;
		width: 50px;
		text-align: center;
	}

	.price {
		position: relative;
		left: 120px;

	}

	.button {
		width: 100px;
	}
</style>
